﻿/*
   这个表可以从server的t_brokenaddr得到，每天自动获取,
 * 可以算出在某个经纪公司产生了多少的盈利或返还等
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/*
    2012-2-17 David检查正常
 */
namespace Benefit.Service.Sys
{
    /// <summary>
    /// 经纪公司
    /// </summary>
    public class ServiceBroker : Benefit.Interface.Sys.IBroker
    {
        Benefit.DB.DBManager db = null;
        public ServiceBroker(Benefit.DB.DBManager db)
        {
            this.db = db;
        }

        /// <summary>
        /// 初始化经纪公司
        /// </summary>
        public void InitBrokers()
        {
            Interface.ServerData.IT_BrokenAddr iba = new ServerData.ServiceT_BrokenAddr(db);
            List<Models.ServerData.T_BrokenAddr> brokers = iba.GetList();
            foreach (Models.ServerData.T_BrokenAddr addr in brokers)
            {
                var query = from t in db.Broker where t.BrokerId.Equals(addr.BrokenId) select t;
                if (query.Count() == 0)
                {
                    Models.Sys.Broker broker = new Models.Sys.Broker();
                    broker.BrokerId = addr.BrokenId;
                    broker.BrokerName = addr.BrokenName;
                    broker.IsDeleted = false;
                    db.Broker.Add(broker);
                }
            }
        }
        /// <summary>
        /// 获取所有经纪公司
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        public List<Models.Sys.Broker> GetList()
        {
            return db.Broker.ToList();
        }
    }
}